package com.example.riskmanage.service.impl;

import com.alibaba.fastjson.JSON;
import com.example.riskmanage.bean.Admin;
import com.example.riskmanage.dao.AdminDao;
import com.example.riskmanage.service.AdminManager;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.HashMap;
import java.util.List;

@Service
public class AdminManagerImpl implements AdminManager {
    /*
            HashMap<String,Object> map = new HashMap<>();

             String respJSON = JSON.toJSONString(map);
             return respJSON;

     */

    @Autowired
    AdminDao adminDao;

    @Override
    public String getAdminService(Integer uid) {
        HashMap<String, Object> map = new HashMap<>();
        //1.调用dao层接口获取数据
        List<Admin> adminList = adminDao.findAllByUid(uid);
        //2.将处理的数据封装到map
        map.put("adminList", adminList);
        map.put("flag", true);

        String respJSON = JSON.toJSONString(map);
        return respJSON;
    }

    public String addAdminService(Admin admin) {

        adminDao.save(admin);


        return "ok";
    }

    @Override
    public String deleteAdminService(Integer id) {

        adminDao.deleteById(id);

        return "ok";
    }

    @Override
    public String geteditService(Integer id) {


        HashMap<String, Object> maps = new HashMap<>();
        //1.调用dao层接口获取数据
        Admin edit = adminDao.findAdminById(id);
        //2.将处理的数据封装到map

        String respJSON = JSON.toJSONString(edit);

        return respJSON;
    }

    @Override
    public String editAdminService(Admin admin) {


        adminDao.save(admin);


        return "ok";
    }
}
